<template>
	<view id="domxee-content" :class="globalData.defaultThemes">
		<view id="header_wrapper">
			<nii-navbar :globalData="globalData" :scroll="scroll" back fixed minPadding back_alias="account.wallets">
				<!-- <view slot="back"></view> -->
				<view slot="title">
					<view id="title" class="fw-bolder">{{renders.main_title}}</view>
				</view>
				<!-- <view slot="tools"></view> -->
			</nii-navbar>
		</view>
		<view id="content_wrapper">
			<view id="transfer">
				<view class="transfer min-padding">
					<view class="transfer_box section">
						<view class="account page_bg d-flex justify-content-between align-items-center">
							<view class="left section d-flex align-items-center">
								<!-- <view class="avatar_box">
									<u--image :src="renders.account.avatar" width="60rpx" height="60rpx" radius="60rpx" mode="aspectFit" :bgColor="globalData.colors.current.section" class="avatar">
									  <template v-slot:loading>
										 <image src="@/static/media/images/loading.png" mode="aspectFit"></image>
									  </template>
									  <template v-slot:error>
										 <image src="@/static/media/images/loading.png" mode="aspectFit"></image>
									  </template>
									</u--image>
								</view> -->
								<view class="infos">
									<view class="nickname u-line-1 fw-bolder text-center">{{renders.account.account_id}}</view>
									<view class="nickname u-line-1 fw-bolder text-center">{{renders.account.nickname}}</view>
									<view class="tip less_text text-center">{{renders.texts.transfer_amount}}</view>
								</view>
							</view>
							<view class="right">
								<view class="name fw-bolder">{{renders.texts.transfer_input.name}}</view>
								<input type="digit" class="input section" placeholder-class="less_text" @blur="computeAmount" v-model="renders.formData.amount" :placeholder="renders.texts.transfer_input.placeholder">
							</view>
						</view>
						<view class="icon page_bg">
							<view class="domxee_icon color fw-bolder iconfont icon-zhuanhuan-yuan-shangxia-F"></view>
						</view>
						<view class="transfer_account page_bg d-flex justify-content-between align-items-center">
							<view class="left d-flex align-items-center section">
								<view class="avatar_box">
									<u--image :src="renders.transfer_account.avatar" width="60rpx" height="60rpx" radius="60rpx" mode="aspectFit" :bgColor="globalData.colors.current.section" class="avatar">
									  <template v-slot:loading>
										 <image src="@/static/media/images/loading.png" mode="aspectFit"></image>
									  </template>
									  <template v-slot:error>
										 <image src="@/static/media/images/loading.png" mode="aspectFit"></image>
									  </template>
									</u--image>
								</view>
								<view class="infos">
									<view class="nickname u-line-1 fw-bolder">{{renders.transfer_account.account_id}}</view>
									<view class="tip less_text">{{renders.transfer_account.mobile}}</view>
								</view>
							</view>
							<view class="right">
								<view class="name less_text">{{renders.texts.transfer_tip}}</view>
								<view class="amount fw-bolder">{{renders.amounts.arrival}}</view>
							</view>
						</view>
						<view class="amounts page_bg">
							<view class="rows">
								<view class="row d-flex justify-content-between align-items-center">
									<view class="name vice_text">{{renders.amounts_texts.amount}}</view>
									<view class="text fw-bolder">{{renders.amounts.amount ? renders.amounts.amount : '-.--'}}</view>
								</view>
								<view class="row d-flex justify-content-between align-items-center">
									<view class="name vice_text">{{renders.amounts_texts.rate}}</view>
									<view class="text fw-bolder">{{renders.amounts.rate}}%</view>
								</view>
								<view class="row d-flex justify-content-between align-items-center">
									<view class="name vice_text">{{renders.amounts_texts.tax}}</view>
									<view class="text fw-bolder">{{renders.amounts.tax}}</view>
								</view>
								<view class="row d-flex justify-content-between align-items-center">
									<view class="name vice_text">{{renders.amounts_texts.arrival}}</view>
									<view class="text fw-bolder color">{{renders.amounts.arrival}}</view>
								</view>
							</view>
						</view>
						<view class="pay_password">
							<view class="title fw-bolder">支付密码验证</view>
							<view class="passwords d-flex justify-content-between align-items-center">
								<!-- <input type="password" maxlength="1" class="inputer page_bg fw-bolder" v-for="(input, index) in data.sections.password.len" @tap="onInput" :key="index" :value="renders.formData.pay_password.length >= index + 1 ? renders.formData.pay_password[index] : ''">
								<input type="number" class="hidden_password" v-if="data.sections.password.focus" @blur="blurInput" @input="setInput" v-model="renders.formData.pay_password" :maxlength="data.sections.password.len" :focus="data.sections.password.inputFocus">
							
								<input type="number" class="hidden_password" v-if="data.sections.password.focus" @blur="blurInput" @input="setInput" v-model="renders.formData.pay_password" :maxlength="data.sections.password.len" :focus="data.sections.password.inputFocus">
							 -->
								<input type="password" maxlength="1" class="inputer page_bg fw-bolder" v-for="(input, index) in data.sections.password.len" @click="onInput" :key="index" :value="renders.formData.pay_password.length >= index + 1 ? renders.formData.pay_password[index] : ''">
							 
								<input type="number" class="hidden_password" v-model="renders.formData.pay_password" :maxlength="data.sections.password.len" :focus="data.sections.password.inputFocus">
							</view>
						</view>
						<view class="button button_bg fw-bolder" @click="action">确认转化</view>
					</view>
				</view>
			</view>
			<view id="tips" v-if="renders.tips">
				<view class="tips d-padding">
					<view class="tips_box">
						<rich-text :nodes="renders.tips" class="row vice_text"></rich-text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				globalData: {windowWidth: 0, statusBarHeight: 0, navHeight: 0, navigationBarHeight: 0, wechatCapsule: {width: 0, height: 0, top: 0, right: 0, bottom: 0, left: 0}, defaultThemes: [], colors: {}, configs: {} },
				scroll: 0,
				current_page: {route: '', params: {}, url: ''},
				ready: false,
				options: {

				},
				styles: {

				},
				shows: {

				},
				renders: {
					main_title: "",
					account: {account_id: 0, mobile: '', nickname: '', avatar: ''},
					transfer_account: {account_id: 0, mobile: '', nickname: '', avatar: ''},
					texts: {transfer_amount: '', transfer_input: {name: '', placeholder: ''}, transfer_tip: ''},
					tips: '',
					formData: {amount: '', type: '', username: '', pay_password: '', user_id: ''},
					amounts_texts: {amount: '', rate: 0, tax: '', arrival: ''},
					amounts: {amount: '', rate: 0, tax: '', arrival: ''}
				},
				data: {
					sections: {
						password: {
							len: 6,
							password: '',
							focus: true,
							inputFocus: false,
						}
					},
				},
			}
		},
		onReady() {						//页面渲染完毕后操作（动态获取/调整元素宽高位置等需在ready后获取最为准确）
			//设置对象
			let that = this;

		},
		onShow() {						//页面显示后操作（关闭、后台运行等操作后重新打开访问触发、可在实时性较高操作页面进行全页刷新）
			//设置对象
			let that = this;
			//判断是否准备就绪
			that.initInformation();
		},
		onLoad(options) {				//页面加载时操作（options可获取当前页面传递参数，如：options.id）
			//设置对象
			let that = this;
			//设置当前页面数据
			that.current_page = that.nii_common.pages.getCurrentUrl();
			//设置默认数据
			that.globalData = that.nii_common.pages.initGlobalData(getApp().globalData);
			//设置参数
			that.options = options;
			//初始数据
			that.initInformation();
		},
		methods: {
			//默认跳转操作
			navigateAction: function(alias, requestParams = {}, action = 'navigate', authenticate = false, animationType = 'slide-in-right') {this.nii_common.navigate.action(alias, requestParams, action, authenticate, animationType); },
			//拨打电话
			callPhone: function(mobile) {uni.makePhoneCall({phoneNumber: mobile});},
			//复制数据
			clipboardData: function (text) {const that = this;that.nii_common.clipboardData(text);},
			initInformation: function() {
				//设置对象
				let that = this;
				//loading
				that.nii_common.toastLoading('请稍候');		
				//发起请求
				that.nii_common.request.build('merchant/exchange_information', that.options, 'GET', function (res) {
					//设置数据
					that.renders = res.data;
				}, function (res) {
					//提示错误
					that.nii_common.toastAlert(res.msg);
					//跳转钱包页面
					// setTimeout(function () {that.navigateAction('account.wallets');}, 1500);
				}, function(res) {
					//隐藏loading
					that.nii_common.toastLoadingHide();
				});	
			},
			onInput: function() {
				//设置对象
				let that = this;
				//设置焦点选中
				that.data.sections.password.focus = true;
				that.$nextTick(() => {
					that.data.sections.password.inputFocus = true;
				});
			},
			setInput: function(e) {
				//设置内容
				this.data.sections.password.password = e.detail.value;
			},
			blurInput: function() {
				//取消焦点
				this.data.sections.password.focus = false;
			},
			computeAmount: function () {
				//设置对象
				let that = this;
				//整理金额
				var amount = parseInt(that.renders.formData.amount * 100), tax_amount = 0, arrival_amount = 0;
				//计算费率
				if (that.renders.amounts.rate > 0) {
					//计算手续费
					tax_amount = parseInt(amount * that.renders.amounts.rate / 100);
				}
				//计算金额
				arrival_amount = amount - tax_amount;
				//设置显示金额内容
				that.renders.amounts.amount = (amount/100).toFixed(2);
				that.renders.amounts.tax = (tax_amount/100).toFixed(2);
				that.renders.amounts.arrival = (arrival_amount/100).toFixed(2);
			},
			action: function() {
				//获取对象
				const that = this;
				//loading
				that.nii_common.toastLoading('处理中...');
				//发起请求
				that.nii_common.request.build('merchant/exchange_action', that.renders.formData, 'POST', function (res) {
					//提示成功
					that.nii_common.toastAlert(res.msg, 'success');
					//跳转钱包页面
					setTimeout(function () {that.navigateAction('merchant.index');}, 1500);
				}, function (res) {
					//提示错误
					that.nii_common.toastAlert(res.msg);
				}, function(res) {
					//隐藏loading
					that.nii_common.toastLoadingHide();
				});	
			}
		},
		onPullDownRefresh(res) {
			//设置对象
			let that = this;
			
			//TODO：页面下拉刷新时的事件
			
			
			//停止刷新
			uni.stopPullDownRefresh();	
		},
		onReachBottom() {
			//设置对象
			let that = this;
			
			//TODO：页面滑动触底时的事件
			
		},
		onPageScroll: function(e) {
			//设置页面滑动高度
			this.scroll = e.scrollTop

			//TODO：需判断滑动高度后处理的事件

		}
	}

</script>

<style lang="scss">
	#header_wrapper {
		#title {
			font-size: 40rpx;
			line-height: 48rpx;
			letter-spacing: 1rpx;
			margin-left: 10rpx;
			font-weight: 600;
		}
		.domxee_icon {			
			font-size: 36rpx;
			line-height: 60rpx;
			margin-right: 20rpx;
		}
		.domxee_icon:last-child {
			margin-right: 0;
		}
	}
	#content_wrapper {
		padding-bottom: 300rpx;
		#transfer {
			margin-top: 40rpx;
			.transfer {
				.transfer_box {
					padding: 40rpx 20rpx 50rpx 20rpx;
					border-radius: 20rpx;
					.account {
						padding: 20rpx 30rpx;
						border-radius: 20rpx;
						.left {
							margin-right: 50rpx;
							padding: 30rpx 10rpx 30rpx 20rpx;
							border-radius: 20rpx;
							.avatar_box {
								width: 60rpx;
								height: 60rpx;
								margin-right: 10rpx;
							}
							.infos {
								.nickname {
									width: 200rpx;
									font-size: 26rpx;
									line-height: 36rpx;
								}
								.tip {
									margin-top: 10rpx;
									font-size: 24rpx;
									line-height: 34rpx;
								}
							}
						}
						.right {
							text-align: right;
							.name {
								font-size: 24rpx;
								line-height: 34rpx;
							}
							.input {
								padding-right: 10rpx;
								margin-top: 10rpx;
								height: 60rpx;
								border-radius: 10rpx;
								font-size: 24rpx;
								line-height: 60rpx;
							}
						}
					}
					.icon {
						margin: 30rpx auto 0 auto;
						width: 100rpx;
						height: 100rpx;
						border-radius: 100rpx;
						text-align: center;
						.domxee_icon {
							font-size: 60rpx;
							line-height: 100rpx;
						}
					}
					.transfer_account {
						margin-top: 30rpx;
						padding: 20rpx 30rpx;
						border-radius: 20rpx;
						.left {
							margin-right: 50rpx;
							padding: 30rpx 10rpx 30rpx 20rpx;
							border-radius: 20rpx;
							.avatar_box {
								width: 60rpx;
								height: 60rpx;
								margin-right: 10rpx;
							}
							.infos {
								.nickname {
									width: 200rpx;
									font-size: 26rpx;
									line-height: 36rpx;
								}
								.tip {
									margin-top: 10rpx;
									font-size: 24rpx;
									line-height: 34rpx;
								}
							}
						}
						.right {
							text-align: right;
							.name {
								font-size: 24rpx;
								line-height: 34rpx;
							}
							.amount {
								margin-top: 10rpx;
								font-size: 32rpx;
								line-height: 44rpx;
							}
						}
					}
					.amounts {
						border-radius: 20rpx;
						margin-top: 30rpx;
						.rows {
							padding: 40rpx 30rpx;
							.row {
								margin-top: 30rpx;
								.name {
									font-size: 24rpx;
									line-height: 34rpx;
								}
								.text {
									font-size: 28rpx;
									line-height: 40rpx;
								}
							}
							.row:first-child {
								margin-top: 0;
							}
						}
					}
					.pay_password {
						margin-top: 30rpx;
						.title {
							font-size: 24rpx;
							line-height: 34rpx;
						}
						.passwords {
							position: relative;
							margin-top: 30rpx;
							z-index: 90;
							overflow: hidden;
							.inputer {
								position: relative;
								width: 100rpx;
								height: 100rpx;
								border-radius: 20rpx;
								line-height: 100rpx;
								font-size: 50rpx;
								text-align: center;
								z-index: 90;
							}
							.hidden_password {
								color: rgba(0, 0, 0, 0);
								opacity: 0;
								height: 100rpx;
								width: 200%;//710rpx;
								position: absolute;
								bottom: 0;
								left: 0;
								transform: translateX(-50%);
								// background-color: black;
								z-index: 100;
								caret-color: transparent; /* 将光标颜色设置为透明 */
							}
						}
					}
					.button {
						margin-top: 30rpx;
						border-radius: 20rpx;
						padding: 22rpx 0;
						width: 670rpx;
						text-align: center;
					}
				}
			}
		}
		#tips {
			margin-top: 50rpx;
			.tips {
				.tips_box {
					.row {
						margin-top: 10rpx;
						font-size: 24rpx;
						line-height: 44rpx;
					}
				}	
			}
		}	
	}
</style>